
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LoginFrameWindow extends JFrame {
    JButton jb1, jb2,jb3;
    JTextField jtf1;
    JPasswordField jtf2;

    public LoginFrameWindow(){
        this.setTitle("登录界面");

        JPanel contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));


        JLayeredPane layeredPane = new JLayeredPane();
        contentPane.add(layeredPane, BorderLayout.CENTER);

        this.add(contentPane);

        // 账户
        JLabel jLabel1 = new JLabel("账号：");
        jLabel1.setBounds(80, 80, 40, 18);
        layeredPane.add(jLabel1);

        jtf1 = new JTextField(10);
        jtf1.setBounds(140, 81, 176, 19);
        layeredPane.add(jtf1);

        // 密码
        JLabel jLabel2 = new JLabel("密码：");
        jLabel2.setBounds(80, 120, 72, 18);
        layeredPane.add(jLabel2);

        jtf2 = new JPasswordField(10);
        jtf2.setEchoChar('*');
        jtf2.setBounds(140, 121, 176, 19);
        layeredPane.add(jtf2);

        // 操作按钮
        jb1 = new JButton("提交");
        jb1.setBounds(80, 160, 72, 23);
        layeredPane.add(jb1);

        jb2 = new JButton("重置");
        jb2.setBounds(160, 160, 72, 23);
        layeredPane.add(jb2);

        jb3 = new JButton("注册");
        jb3.setBounds(240, 160, 72, 23);
        layeredPane.add(jb3);

        jb1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username =jtf1.getText();
                String passwd =new String(jtf2.getPassword());

                System.out.println("用户名是："+username);
                System.out.println("密码是："+passwd);

                if (username.equals("admin") && passwd.equals("123456")){
                    JFrame jf2 =new JFrame();
                    JLabel jl2 =new JLabel("恭喜你，登录成功");
                    jl2.setFont(new Font("宋体",Font.PLAIN,35));
                    jf2.add(jl2);
                    jf2.setSize(500,500);
                    jf2.setLocationRelativeTo(null);
                    jf2.setVisible(true);
                }
                else {
                    JOptionPane.showMessageDialog(null,"登录失败","失败",JOptionPane.INFORMATION_MESSAGE);
                }
            }
        });

        jb2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jtf1.setText("");
                jtf2.setText("");
            }
        });

        jb3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                RegisterInterface registerInterface =new RegisterInterface();
               registerInterface.setVisible(true);


            }
        });

        this.setVisible(true);

        jtf1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String username =jtf1.getText();
                String passwd =new String(jtf2.getPassword());

                if (passwd.equals(""));
                JOptionPane.showConfirmDialog(null,"请输入密码","密码缺失",JOptionPane.INFORMATION_MESSAGE);
                jtf2.requestFocusInWindow();
            }
        });

        this.setVisible(true);
        this.setSize(400,400);

        this.setLocationRelativeTo(null);
    }


    public static void main(String[] args) {
        new LoginFrameWindow();
    }
}

